package CtrlLayer;

import ModelLayer.*;
import DBLayer.*;
import java.util.ArrayList;
/**
 * CtrlProduct.java
 * @author Brian Lassen
 * @version 21. Marts 2012
 */
public class CtrlProduct
{
    public CtrlProduct(){}
    
    public static ArrayList<Product> findAllProducts()
    {
        IFDBProduct dbProduct = new DBProduct();
        ArrayList<Product> allProducts = new ArrayList<Product>();
        allProducts = dbProduct.getAllProducts(false);
        return allProducts;
    }
    
	public static Product findById(int id)
	{
	    IFDBProduct dbProduct = new DBProduct();
	    return dbProduct.searchProductId(id, true);
	}
	
	public static Product findByName(String name)
	{
	    IFDBProduct dbProduct = new DBProduct();
	    return dbProduct.searchProductName(name, true);
	}

    public static int updateProduct(int id, String name, int purchasePrice, int salesPrice, int rentPrice, String coo, int minStock, int supId)
	{
	    IFDBProduct  dbProduct = new DBProduct ();
	    Product prod = new Product();
	    prod.setId(id);
	    prod.setName(name);
	    prod.setPurchasePrice(purchasePrice);
	    prod.setSalesPrice(salesPrice);
	    prod.setRentPrice(rentPrice);
	    prod.setCountryOfOrigin(coo);
	    prod.setMinStock(minStock);
	    prod.setSupplyerid(supId);
	    return dbProduct.updateProduct(prod);
	}
	
	public static void createProduct(int id, String name, int purchasePrice, int salesPrice, int rentPrice, String coo, int minStock, int supId)
	{
	    IFDBProduct dbProduct = new DBProduct();
	    Product prod = new Product();
	    prod.setId(id);
	    prod.setName(name);
	    prod.setPurchasePrice(purchasePrice);
	    prod.setSalesPrice(salesPrice);
	    prod.setRentPrice(rentPrice);
	    prod.setCountryOfOrigin(coo);
	    prod.setMinStock(minStock);
	    prod.setSupplyerid(supId);
	    dbProduct.createProduct(prod);
	   }
	   
	   public static void deleteProduct(int id)
	   {
	       IFDBProduct dbProduct = new DBProduct();
	       dbProduct.deleteProduct(id);
	   }
}